package restaurant.selector.server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import restaurant.selector.logic.LogicInterface;

public class Server implements Runnable {

	private ExecutorService executor;
	private ServerSocket serverSocket;
	private LogicInterface logic;
	
	public Server( int port, LogicInterface logic ) throws IOException{
		
		this.logic = logic;
		serverSocket = new ServerSocket(port);
		executor = Executors.newFixedThreadPool(10);
	}

	@Override
	public void run() {
		while( true ){
			
			try {
				Socket socket = serverSocket.accept();
				executor.execute( new ServerHandler(socket, logic) );
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
